package common

import (
	"net/http"
	"sync"
)

type Request struct {
	*SpiderContext
	*http.Request
}

var httpRequestFree = sync.Pool{
	New: func() interface{} { return new(http.Request) },
}

func newHttpRequest() *http.Request {
	return httpRequestFree.Get().(*http.Request)
}
func NewRequestWithContext(context *SpiderContext) *Request {
	return &Request{SpiderContext: context}
}
func (self *Request) NewRequest(url string) (*Request, error) {
	var err error
	self.Request, err = http.NewRequest("GET", url, nil)
	if err != nil {
		return nil, err
	}
	return self, nil
}
func (self *Request) Response() *Response {
	return &Response{Request: self}
}
